package com.jams.goodox.entity.resp;

import com.jams.goodox.activity.serve.park.ParkingApplyActivity;
import com.jams.goodox.entity.Mapper;
import com.jams.goodox.entity.PageInfo;
import com.jams.goodox.entity.ParkHistoryBean;
import com.jams.goodox.entity.PayInfo;
import com.jams.goodox.net.BaseEntity;
import com.jams.goodox.utils.StringUtils;
import com.jams.goodox.utils.Utils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by guozhen.hou on 2017/6/21.
 */

public class ParkHistoryResp extends BaseEntity{

    private DataBean data;

    public DataBean getData() {
        return data;
    }

    public void setData(DataBean data) {
        this.data = data;
    }

    public static class DataBean implements Mapper<List<ParkHistoryBean>>{
        private PageInfo pageInfo;
        private List<ResultListBean> resultList;

        public PageInfo getPageInfo() {
            return pageInfo;
        }

        public void setPageInfo(PageInfo pageInfo) {
            this.pageInfo = pageInfo;
        }

        public List<ResultListBean> getResultList() {
            return resultList;
        }

        public void setResultList(List<ResultListBean> resultList) {
            this.resultList = resultList;
        }

        @Override
        public List<ParkHistoryBean> transform() {
            List<ParkHistoryBean> parkHistoryBeanList=new ArrayList<>();
            if(resultList!=null&&resultList.size()>0){
                for (ResultListBean resultListBean:resultList){
                    parkHistoryBeanList.add(resultListBean.transform());
                }
            }
            return parkHistoryBeanList;
        }

        public static class ResultListBean implements Mapper<ParkHistoryBean>{
            private String busId;
            private int buyNum;
            private String carNum;
            private String endTime;
            private String identity;
            private String isStatus;
            private String menuCost;
            private String menuType;
            private String moneyType;
            private String orderId;
            private double orderMoneyReal;
            private double orderMoneyTotal;
            private String orderNum;
            private String orderStatus;//订单状态 1.待付款2 已完成3已关闭
            private PayInfo pay;
            private String redPacketId;
            private String redPacketMoney;
            private String referTime;
            private String startTime;
            private String status;
            private String subId;
            private String subName;
            private String subPayType;
            private String userId;
            private String isNew;//是否可续约

            @Override
            public ParkHistoryBean transform() {
                ParkHistoryBean parkHistoryBean=new ParkHistoryBean();
                parkHistoryBean.setPay(pay);
                parkHistoryBean.setCarNum(carNum);
                String unit;
                if (ParkingApplyActivity.Type_Menu_Month == StringUtils.toInt(menuType)) {
                    unit = "月";
                } else {
                    unit = "年";
                }
                parkHistoryBean.setUnitPriceNum(String.format("%s元/%s x%s", Utils.getIntByStr(menuCost),unit,buyNum));
                parkHistoryBean.setContinueTime(String.format("%s~%s", startTime, endTime));
                parkHistoryBean.setParkType(getParkType());
                parkHistoryBean.setEnTime(status);
                parkHistoryBean.setOrderNo(orderNum);
                parkHistoryBean.setOrderId(orderId);
                parkHistoryBean.setRedPicketMoney(StringUtils.stringToDouble(redPacketMoney));
                parkHistoryBean.setOrderAllPay(orderMoneyTotal);
                parkHistoryBean.setCanContinuePark("0".equalsIgnoreCase(isNew));
                return parkHistoryBean;
            }
            /**
             * 转换订单状态
             * //orderStatus 订单状态 1.待付款2 已完成3已关闭 isStatus 订单状态是否过期 0过期,1正常
             * 当订单状态为3 or isStatus为0时，应为过期or关闭，需要灰显状态值等
             * 当订单状态为 1，待付款
             * 订单状态为2 完成可续约
             * @return
             */
            private String getParkType(){
                if("3".equalsIgnoreCase(orderStatus)||"0".equalsIgnoreCase(isStatus))return ParkHistoryBean.Type_Park_Past_Close;
                if("1".equalsIgnoreCase(orderStatus))return ParkHistoryBean.Type_Park_Need_pay;
                if("2".equalsIgnoreCase(orderStatus))return ParkHistoryBean.Type_Park_Commend;
                else return "";
            }
        }
    }


}
